package com.k7k7.sserver.room;

import org.dom4j.Element;

import java.util.Vector;

public class RoomMgr {
	private static RoomMgr instance;

	public static RoomMgr getInstance() {
		if (instance == null) {
			instance = new RoomMgr();
		}
		return instance;
	}

	Vector<Room> rooms;
	public static int max_room = 10;

	private RoomMgr() {
		this.rooms = new Vector<Room>();
		for (int i = 0; i < RoomMgr.max_room; i++) {
			Room s = new Room(String.valueOf(i + 1));
			this.rooms.add(s);
		}
	}

	public Room getRoomByID(String roomID) {
        for (Room next : rooms) {
            if (next.getRoomID().equals(roomID.trim())) {
                return next;
            }
        }
		return null;
	}

	public Room getRoomCanEnter() {
        for (Room next : rooms) {
            if (next.canEnter()) {
                return next;
            }
        }
		return null;
	}

	public void sendToAllRoom(Element info) {
        for (Room next : rooms) {
            next.sendToAllClients(info);
        }
	}
}
